#ifndef BLOCK_H
#define BLOCK_H

#pragma warning(disable:4996)
#include <string>
#include <vector>
#include <fstream>
#include <cassert>
#include <cstdarg>
#include <cstdio>

#include <boost/serialization/access.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
using namespace std;

template<class T>
class DataBlock {
	friend boost::serialization::access;
	template<class Archive>
	void serialize(Archive & ar, const unsigned int version)
	{
		ar & dataSet;
		ar & start;
		ar & count;
	}
private:
	unsigned int count;
	unsigned int start;
public :
	DataBlock();
	DataBlock(unsigned int s, unsigned int size);
	~DataBlock();
	void Add(T data);
	string GetFileName(const char * filefmt, ...);
	unsigned int GetCount() {return count; }
	unsigned int GetStartIndex() {return start; }
	void FixSize() {
		if (count != dataSet.size()) {
			dataSet.resize(count);
		}
	}
	vector<T> dataSet;
};

template<class T>
DataBlock<T>::DataBlock(): start(0), count(0) {}

template<class T>
DataBlock<T>::DataBlock(unsigned int s, unsigned int size): start(s), count(0){
	dataSet.resize(size);
}

template<class T>
DataBlock<T>::~DataBlock(){}

template<class T>
void DataBlock<T>::Add(T data) {
	dataSet[this->count++] = data;
}

template<class T>
string DataBlock<T>::GetFileName(const char * filefmt, ...) {
	char buffer[512];
	va_list args;
	va_start(args, filefmt);
	vsprintf(buffer, filefmt, args);
	va_end(args);
	string filename(buffer);
	return filename;
}
#endif